﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Icoders.MarketTracker.Reports.Lib.Domain;
using Icoders.MarketTracker.Reports.Lib.Repository.Transactions;
using Icoders.MarketTracker.Reports.Lib.Util;
using Microsoft.Reporting.WebForms;
using StructureMap;

namespace Icoders.MarketTracker.Web.rpt.Admin
{
    public partial class PointOfPurchaseReport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadReport();
            }
        }

        private void LoadReport()
        {
            IReportRepository _reportRepository = ObjectFactory.GetInstance<IReportRepository>();
            ReportViewer1.Reset();
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.ProcessingMode = ProcessingMode.Local;
            ReportViewer1.LocalReport.EnableHyperlinks = true;

            var stream =
                Assembly.GetAssembly(typeof (ReportBase)).GetManifestResourceStream(
                    ReportCollective.PointOfPurchaseReport);
            ReportDataSource reportDataSource = new ReportDataSource("PointOfpurchaseDataset",
                                                                     _reportRepository.GetPointOfPurchase());
            ReportViewer1.LocalReport.DataSources.Add(reportDataSource);
            ReportViewer1.LocalReport.LoadReportDefinition(stream);

            ReportViewer1.LocalReport.DisplayName = "Point Of Purchase";
            ReportViewer1.LocalReport.Refresh();
        }
    }
}